﻿using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;

namespace zDit.Core
{
    public static class PagedListExtension
    {
        //public static List<T> GetPageList<T>(this IEnumerable<T> source, int pageIndex, int pageSize)
        //{
        //    return GetEnumerable(source, pageIndex, pageSize).ToList<T>();
        //}
        //public static IEnumerable<T> GetEnumerable<T>(this IEnumerable<T> source, int pageIndex, int pageSize)
        //{
        //    return source.Skip(pageIndex*pageSize).Take(pageSize);
        //}
        public static PagedList<T> ToPagedList<T>(this IEnumerable<T> source, int pageIndex, int pageSize)
        {
            return new PagedList<T>(source, pageIndex, pageSize, source.Count());
        }

        public static PagedList<T> ToPagedList<T>(this IQueryable<T> linq, int pageIndex, int pageSize)
        {
            return new PagedList<T>(linq, pageIndex, pageSize);
        }
        public static PagedList<T> ToPagedList<T>(this IList<T> source, int pageIndex, int pageSize)
        {
            return new PagedList<T>(source, pageIndex, pageSize);
        }

        public static JsonPagedList<T> ToJsonPagedList<T>(this IList<T> source, int pageIndex, int pageSize)
        {
            return new JsonPagedList<T>(source, pageIndex, pageSize);
        }

        public static JsonPagedList<T> ToJsonPagedList<T>(this IQueryable<T> source, int pageIndex, int pageSize)
        {
            return new JsonPagedList<T>(source, pageIndex, pageSize);
        }
        public static JsonPagedList<T> ToJsonPagedList<T>(this IEnumerable<T> source, int pageIndex, int pageSize)
        {
            return new JsonPagedList<T>(source.AsQueryable<T>(), pageIndex, pageSize);
        }
    }
}